*********************************************************************************************************************************************
* This code replicates all main tables in 
* "Joining Forces: The Spillover Effects of EPA Enforcement Actions and the Role of Socially Responsible Investors"																		
* The program uses the original datasets (constructed using SAS codes) to run regressions for each table in the paper. 
**********************************************************************************************************************************************
 *Table 2:
use "peertri.dta", clear
drop if sdonsite==. 
reghdfe sdonsite treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store x1, title(Model 1)
reghdfe lnrsei_score treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store x2, title(Model 2)
reghdfe sdonsite treat_post1 size bm roa   lnsale lev , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store x3, title(Model 3)
reghdfe lnrsei_score treat_post1 size bm roa   lnsale lev, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store x4, title(Model 4)
reghdfe sdonsite treat_post1 treat_close_pre1 treat_close_pre2, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store y1, title(Model 1)
reghdfe lnrsei_score treat_post1 treat_close_pre1 treat_close_pre2, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store y2, title(Model 2)
reghdfe sdonsite treat_post1 treat_close_pre1 treat_close_pre2 size bm roa   lnsale lev , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store y3, title(Model 3)
reghdfe lnrsei_score treat_post1 treat_close_pre1 treat_close_pre2 size bm roa   lnsale lev, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store y4, title(Model 4)

 *Table 3: SRMFs
 use "peertrimf.dta", clear
drop if sdonsite==. 
reghdfe sdonsite treat_close_post_closemf  treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster  dunsnumber  year) 
estimates store x1, title(Model 1)
reghdfe lnrsei_score treat_close_post_closemf  treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber  year) 
estimates store x2, title(Model 2)
reghdfe sdonsite treat_close_post_closemf  treat_post1 treat_close_post_closemf1  treat_close_post_closemf3, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber  year) 
estimates store x3, title(Model 3)
reghdfe lnrsei_score treat_close_post_closemf  treat_post1 treat_close_post_closemf1  treat_close_post_closemf3 , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber  year ) 
estimates store x4, title(Model 4)
 use "peertrimf.dta", clear
drop if sdonsite==. 
reghdfe sdonsite treat_close_post_closemf  treat_post1  treat_pre1_closemf treat_pre2_closemf treat_close_pre1 treat_close_pre2   , absorb( dunsnumber#cohort year#cohort ) vce(cluster  dunsnumber  year  ) 
estimates store x1, title(Model 1)
reghdfe lnrsei_score treat_close_post_closemf treat_post1 treat_pre1_closemf treat_pre2_closemf  treat_close_pre1 treat_close_pre2 ,  absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber  year ) 
estimates store x2, title(Model 1)
*Table 3: matched sample
use "peertrimf.dta", clear 
reghdfe sdonsite treat_close_post_closemf  treat_post1 treat_close_post_closemf1  treat_close_post_closemf3, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber  year) 
estimates store x1, title(Model 1)
reghdfe lnrsei_score treat_close_post_closemf  treat_post1 treat_close_post_closemf1  treat_close_post_closemf3 , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber  year ) 
estimates store x2, title(Model 2)

*Table 4: inspection
use "peertrimf_inspect.dta", clear 
g lnnum_inspection=ln(1+num_inspection)
reghdfe lnnum_inspection   treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster  dunsnumber year) 
estimates store x1, title(Model 1)
reghdfe inspect   treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster  dunsnumber year ) 
estimates store x2, title(Model 2)
reghdfe lnnum_inspection treat_close_post_closemf  treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster  dunsnumber year) 
estimates store x3, title(Model 3)
reghdfe inspect treat_close_post_closemf   treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year ) 
estimates store x4, title(Model 4)

*Table 5: MF taxi trips
use "plantmf_level.dta", clear
g treat_post_srmf=treat1*post1*srmf
g srmf_post=srmf*post1
g treat_srmf=treat1*srmf
g lnnum_mftrip=ln(1+num_mftrip)
reghdfe mfvisit treat_post_srmf treat_post srmf_post treat_srmf, absorb( dunsnumber#cohort wficn2#cohort year#cohort)  vce(cluster  wficn2  dunsnumber) 
estimates store x1, title(Model 1)
reghdfe lnnum_mftrip treat_post_srmf treat_post srmf_post treat_srmf, absorb( dunsnumber#cohort wficn2#cohort year#cohort)  vce(cluster wficn2  dunsnumber) 
estimates store x2, title(Model 2)

*Table 6 : SRMFs portfolio holding
use "mfshare1.dta", clear
drop if lweight==.
replace nxtyr_weight=nxtyr_weight*100
replace nxtyr_weight=0 if nxtyr_weight==.
replace lweight=lweight*100
replace nxt2yr_weight=nxt2yr_weight*100
replace nxt2yr_weight=0 if nxt2yr_weight==.
g dweight=nxtyr_weight-lweight
g d2weight=nxt2yr_weight-lweight
g treatfirmpost_closemf_nrespond=treatfirmpost_closemf*nonrespond1
g treatfirmpost_nrespond=treatfirm_post*nonrespond1
reghdfe dweight  treatfirmpost_closemf_nrespond treatfirmpost_closemf treatfirmpost_nrespond treatfirm_post  ln_fsize exp_ratio turn_ratio rret fund_flows, absorb( wficn gvkey1 year ) vce(cluster wficn vkey1) 
estimates store x1, title(Model 1)
reghdfe dweight treatfirmpost_closemf_nrespond treatfirmpost_closemf treatfirmpost_nrespond treatfirm_post ln_fsize exp_ratio turn_ratio rret fund_flows, absorb( wficn sic2 year ) vce(cluster wficn sic2 ) 
estimates store x2, title(Model 1)
reghdfe d2weight  treatfirmpost_closemf_nrespond treatfirmpost_closemf treatfirmpost_nrespond treatfirm_post  ln_fsize exp_ratio turn_ratio rret fund_flows, absorb( wficn gvkey1 year ) vce(cluster wficn vkey1) 
estimates store x3, title(Model 3)
reghdfe d2weight treatfirmpost_closemf_nrespond treatfirmpost_closemf treatfirmpost_nrespond treatfirm_post ln_fsize exp_ratio turn_ratio rret fund_flows, absorb( wficn sic2 year ) vce(cluster wficn sic2 ) 
estimates store x4, title(Model 4)

*Table 7: Treated Plants' Pollution Abatement Activities
use "peertrimf_process.dta", clear
reghdfe process treat_close_post_closemf treat_post1 , absorb( dunsnumber#cohort year#cohort  ) vce(cluster dunsnumber year ) 
estimates store x1, title(Model 1)
reghdfe practice treat_close_post_closemf treat_post1 , absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year) 
estimates store x2, title(Model 2)

*Table 8: distant plants pollution reduction  - short-run
use "distpeertrimf.dta", clear 
reghdfe process  treatfirm_closemf_post treat_post1 , absorb( dunsnumber#cohort year#cohort )  vce(cluster dunsnumber year ) 
estimates store x1, title(Model 1)
reghdfe practice  treatfirm_closemf_post treat_post1 , absorb( dunsnumber#cohort year#cohort  )  vce(cluster dunsnumber year) 
estimates store x2, title(Model 2)
*Table 8: distant plants pollution reduction - long-run
use "distpeertrimf_lt.dta", clear
reghdfe process  treatfirm_closemf_post treat_post1 , absorb( dunsnumber#cohort year#cohort )  vce(cluster  dunsnumber year ) 
estimates store x3, title(Model 3)
reghdfe practice  treatfirm_closemf_post treat_post1 , absorb( dunsnumber#cohort year#cohort )  vce(cluster dunsnumber year ) 
estimates store x4, title(Model 4)

*Table 9 : Long-Run Responses
use "peertrimf_lt.dta", clear 
drop if sdonsite==. 
reghdfe sdonsite treat_post1, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year) 
estimates store x1, title(Model 1)
reghdfe lnrsei_score treat_post1, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year) 
estimates store x2, title(Model 2)
reghdfe sdonsite treat_close_post_closemf treat_post1, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year) 
estimates store x3, title(Model 3)
reghdfe lnrsei_score treat_close_post_closemf treat_post1, absorb( dunsnumber#cohort year#cohort ) vce(cluster dunsnumber year) 
estimates store x4, title(Model 4)
g treat_close_post_nres_mf=treat_post1*local_nrespond*closemfnres
g treat_close_post_nres=treat_post1*local_nrespond
reghdfe sdonsite  treat_close_post_nres  treat_post1 , absorb( dunsnumber#cohort year#cohort  ) vce(cluster dunsnumber year) 
estimates store y3, title(Model 1)
reghdfe lnrsei_score  treat_close_post_nres treat_post1 , absorb( dunsnumber#cohort year#cohort  ) vce(cluster dunsnumber year) 
estimates store y4, title(Model 2)
reghdfe sdonsite treat_close_post_nres_mf treat_close_post_nres  treat_post1 , absorb( dunsnumber#cohort year#cohort  ) vce(cluster dunsnumber year) 
estimates store y3, title(Model 3)
reghdfe lnrsei_score  treat_close_post_nres_mf treat_close_post_nres treat_post1 , absorb( dunsnumber#cohort year#cohort  ) vce(cluster dunsnumber year) 
estimates store y4, title(Model 4)

*Table 10: Firm-level
use "peertrimf_firm0.dta", clear
reghdfe sdonsite treat_close_post_closemf treat_post1, absorb( gvkey1#cohort year#cohort ) vce(cluster gvkey1) 
estimates store x1, title(Model 1)
reghdfe lnrsei_score treat_close_post_closemf treat_post1, absorb( gvkey1#cohort year#cohort) vce(cluster gvkey1) 
estimates store x2, title(Model 1)
use "peertrimf_firm.dta", clear
reghdfe sdonsite  treat_close_post_closemf treat_post1, absorb( gvkey1#cohort year#cohort) vce(cluster gvkey1 ) 
estimates store x3, title(Model 3)
reghdfe lnrsei_score treat_close_post_closemf treat_post1, absorb(gvkey1#cohort year#cohort) vce(cluster gvkey1)
estimates store x4, title(Model 4)
use "peertrimf_firm.dta", clear
reghdfe roa treat_post1_reduonsite treat_post1 size bm lev , absorb( gvkey1#cohort year#cohort) vce(cluster gvkey1 ) 
estimates store y1, title(Model 1)
reghdfe roa treat_post1_redursei treat_post1 size bm lev, absorb( gvkey1#cohort year#cohort) vce(cluster gvkey1) 
estimates store y2, title(Model 2)
reghdfe roa treat_post1_reduonsite treat_post1 treat_close_post_closemf treat_post1_closemf_reduonsite size bm lev, absorb( gvkey1#cohort year#cohort) vce(cluster gvkey1) 
estimates store y3, title(Model 3)
reghdfe roa treat_post1_redursei treat_post1 treat_close_post_closemf treat_post1_closemf_redursei size bm lev, absorb( gvkey1#cohort year#cohort) vce(cluster gvkey1)
estimates store y4, title(Model 4)